﻿using KayakMes.Common.Dtos.BasicSettingDTO.Input;
using KayakMes.Common.Result;
using KayakMes.Units.Application;
using KayakMes.Units.Domain.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KayakMes.Units.Api.Controllers
{
    /// <summary>
    /// 基础设置
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UnitsController : ControllerBase
    {
        private readonly IBasicSettingService basicSettingService;
        /// <summary>
        /// 通过构造函数注入基础设置服务
        /// </summary>
        /// <param name="basicSettingService">基础设置服务实例</param>
        public UnitsController(IBasicSettingService basicSettingService)
        {
            this.basicSettingService = basicSettingService;
        }
        #region 计量单位相关接口
        /// <summary>
        /// 添加计量单位
        /// </summary>
        /// <param name="units">计量单位模型</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPost]
        public ApiResult<int> AddUnits(UnitsModel units)
        {
            return basicSettingService.AddUnits(units);
        }
        /// <summary>
        /// 获取所有计量单位（支持分页查询）
        /// </summary>
        /// <param name="dto">计量单位查询条件DTO</param>
        /// <returns>返回分页查询的计量单位列表</returns>
        [HttpGet]
        public ApiPaging<UnitsModel> GetAllUnits([FromQuery]UnitsDto dto)
        {
            return basicSettingService.GetAllUnits(dto);
        }
        /// <summary>
        /// 根据ID获取指定的计量单位
        /// </summary>
        /// <param name="Id">计量单位ID</param>
        /// <returns>返回操作结果，包含指定的计量单位订单信息</returns>
        [HttpGet]
        public ApiResult<UnitsModel> GetUnits(long Id)
        {
           return basicSettingService.GetUnits(Id);
        }
        /// <summary>
        /// 更新计量单位
        /// </summary>
        /// <param name="units">计量单位模型</param>
        /// <returns>返回操作结果</returns>
        [HttpPut]
        public ApiResult<int> UpdateUnits(UnitsModel units)
        {
            return basicSettingService.UpdateUnits(units);
        }
        /// <summary>
        /// 删除计量单位
        /// </summary>
        /// <param name="Id">计量单位Id</param>
        /// <returns>返回操作结果</returns>
        [HttpDelete]
        public ApiResult<int> LoginDel(long Id)
        {
            return basicSettingService.LoginDel(Id);
        }
        #endregion
    }
}
